package com.tuyou.springboot.redis;

import com.tuyou.springboot.comon.po.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Repository;

@Repository
public class UserRedisRepository {

//    @Autowired
//    private StringRedisTemplate stringRedisTemplate;

//    @Resource(name = "stringRedisTemplate")
//    private ValueOperations<String, String> valOpsStr;

    @Autowired
    private RedisTemplate<String, Object> redisTemplate;
//
//    @Resource(name = "redisTemplate")
//    private ValueOperations<Object, Object> valOps;

    public void stringRedisTemplateDemo() {
        redisTemplate.opsForValue().set("xx", "yy");
    }

    public void save(User user) {
        redisTemplate.opsForValue().set(user.getId()+"", user);
    }

    public String getString() {
        return (String)redisTemplate.opsForValue().get("xx");
    }

    public User getUser() {
        return (User)redisTemplate.opsForValue().get("1");
    }
}
